<?php

if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
if ($curruser['acl'] != 255)
{
    exit();
}
$gametype = intval(getvar("gametype"));

if (!isset($_SESSION['CHK_master_account_OK']) || $_SESSION['CHK_master_account_OK'] != 1)
{
   	header("Location: op.php?op=admin&fp=amountchkpass&gametype={$gametype}&t=-1");
    exit();
}

include_once( "class_3d/CheckMode_3d.php" );
require_once( "class_sb/RateConfig_sb.php" );
include_once( "ip/ip_fun.php" );
$ipfun=new QQWry();
$chk = new CheckMode_3d($curruser['acl'], 1, $gametype);
$chk->checkShow3dPage();
$show3D3S = $chk->show3D3S;
unset($chk);
$ui = new UI_3D(true);
$tpl = new Template2();
$conf = new Config();
$gametypeCHK = "";
$dataList = "";
$pagelink = "";
$postTime = $conf->get("paper_post_bet");
$today = date("Hi") <= $postTime ? date("Y-m-d", strtotime("-1 day")) : date("Y-m-d");
$dt1 = getvar("dt1");
$dt2 = getvar("dt2");
$dt1 = $dt1 == "" ? $today : $dt1;
$dt2 = $dt2 == "" ? $dt1 : $dt2;
$page = intval(getvar("page"));
$RateConfig_sb=new RateConfig_sb(25);
if ($page == 0)
{
    $page = 1;
}
$chkRameArr = isset($_POST['chkRame']) ? $_POST['chkRame'] : array(0, 1, 2, 3, 4, 9);
$chkGameArr = isset($_POST['chkGame']) ? $_POST['chkGame'] : array();
$user_id = getvar("user_id");
if (ispost() || 0 < count($chkGameArr))
{
    $dt1t = strtotime($dt1);
    $dt2t = strtotime($dt2);
    if (count($chkRameArr) < 1)
    {
        exit("请选注单状态");
    }
    $littleNum = 0;
    $littleAmount = 0;
    $littleBack = 0;
    $littleB1 = 0;
    $sqlArr = array();
    $checkedArr = array();
    while ($dt1t <= $dt2t)
    {
        $dt1Str = date("Ymd", $dt1t);
        $dt2Str = date("Y-m-d", $dt1t);
        $rames = implode(",", $chkRameArr);
        foreach ($chkGameArr as $val)
        {
            $val = intval($val);
            $checkedArr[$val] = " checked ";
            $en = $g_gametype_3d[$val]['en'];
            if ($en == '6h')
            {
                $sql = " SELECT A.id,A.lotto_id,A.createtime,A.user_id,A.bettype,'' as subid,A.numbers,A.line_nums,A.disk,A.back1,A.amount,A.rate,A.a1,A.b1,A.rame,A.ip,A.sessid, C.open, C.round, D.account, {$val} as gametype FROM bet A " . " left join lotto C ON C.id=A.lotto_id left join k_user D ON A.user_id=D.id " . " WHERE C.open='{$dt2Str}' and rame in ({$rames})";
            }
            else
            {
                $sql = " SELECT A.id,A.lotto_id,A.createtime,A.user_id,A.bettype,A.subid,A.numbers,A.line_nums,A.disk,A.back1,A.amount,A.rate,A.a1,A.b1,A.rame,A.ip,A.sessid, C.open, C.round, D.account, {$val} as gametype FROM bet_{$en} A " . " left join lotto_{$en} C ON C.id=A.lotto_id " . " left join k_user D ON A.user_id=D.id " . " WHERE C.open='{$dt2Str}' and rame in ({$rames})";
            }
            if (0 < strlen($user_id))
            {
                $sql .= " and D.account='{$user_id}'";
            }
            $sqlArr[] = $sql;
        }
        $dt1t += 86400;
    }
    if (count($sqlArr) == 0)
    {
        return;
    }
    $sqlStr = implode(" union all ", $sqlArr);
    $rs = getdb($sqlStr . " order by gametype ASC, id DESC ", $page, 50);
    $g_betname_3or5Arr = array();
    foreach ($g_gametype_3d as $gameid => $val)
    {
        if ($gameid == 0)
        {
            $g_betname_3or5Arr[0] = array();
        }
        else
        {
            $g_betname_3or5Arr[$gameid] = judge_type($gameid, true);
        }
    }
    while (!$rs->eof)
    {
        $dataList .= "<tr class=\"td2\">" . ( "<td nowrap><font color=\"green\">" ) . $rs->f['id'] . "</font>&nbsp;&nbsp;" . date("m-d H:i:s", $rs->f['createtime']) . "</td>" . "<td nowrap>" . $rs->f['account'] . "&nbsp;&nbsp;<font color=\"green\">" . ( 100 - $rs->f['back1'] ) . "</font></td>" . "<td nowrap class=\"paper" . $g_gametype_3d[$rs->f['gametype']]['en'] . "\">" . $g_gametype_3d[$rs->f['gametype']]['ch'] . "</td>" . "<td nowrap>" . $g_disk_name[$rs->f['disk']] . "&nbsp;/&nbsp;" . $rs->f['round'] . "期&nbsp;<font color=\"green\">" . $rs->f['open'] . "</font></td>";
		if($rs->f['gametype']==25 || $rs->f['gametype']==26)
			$dataList .= "<td nowrap>【" . $g_betname_3or5Arr[$rs->f['gametype']][$rs->f['bettype']] . "】&nbsp;" . $RateConfig_sb->getBetContent($rs->f['bettype'],$rs->f['line_nums']) . "</td>";
		else
			$dataList .="<td nowrap>【" . $g_betname_3or5Arr[$rs->f['gametype']][$rs->f['bettype'] . "_" . $rs->f['subid']] . "】&nbsp;" . nl2br($rs->f['line_nums']) . "</td>";
        if (20000 < $rs->f['amount'])
        {
            $color = "alert2";
        }
        else if (10000 < $rs->f['amount'])
        {
            $color = "alert1";
        }
        else
        {
            $color = "";
        }
        $dataList .= "<td nowrap align=\"right\" class=\"" . $color . "\">" . $rs->f['amount'] . "</td>";
        $dataList .= "<td nowrap align=\"right\">" . floatval($rs->f['rate']) . "</td>";
        $dataList .= "<td  nowrapalign=\"right\">" . round($rs->f['a1'], 2) . "</td>";
        $dataList .= "<td nowrap align=\"right\">" . say_numbercolor($rs->f['b1']) . "</td>";
        if ($rs->f['rame'] == 1)
        {
            $note = "<font color=red>- 逾时 -</td>";
        }
        else if ($rs->f['rame'] == 2)
        {
            $note = "<font color=red>- 取消 -</td>";
        }
        else if ($rs->f['rame'] == 3)
        {
            $note = "<font color=red>- 异常 -</td>";
        }
        else
        {
            $note = "";
            $littleNum += 1;
            $littleAmount += $rs->f['amount'];
            $littleBack += $rs->f['a1'];
            $littleB1 += $rs->f['b1'];
        }
        $dataList .= "<td nowrap>{$note}</td>";
		$ipfun->QQWry($rs->f['ip']); 
		$area=$ipfun->Country;
        $tempIp = $rs->f['ip'];
        $dataList .= "<td nowrap>{$tempIp}({$area})</td>";
        $chksessid = getSessidStatus(chkBetSessid($rs->f, $rs->f['sessid']));
        $dataList .= "<td nowrap>{$chksessid}</td>";
        $dataList .= "<td nowrap><a href=\"?op.php?op=admin&fp=b2&gametype={$rs->f['gametype']}&id={$rs->f['id']}\" target=\"_blank\">更改</a></td>";
        $dataList .= "</tr>";
        $rs->next();
    }
    $tpl->set("chkRameArr", serialize($chkRameArr));
    $tpl->set("chkGameArr", serialize($chkGameArr));
    $pagelink = $rs->pageLink(FALSE);
    $rs->close();
}
else
{
    foreach ($g_gametype_3d as $key => $val)
    {
        $checkedArr[$key] = " checked ";
    }
}
$gametypeCHK = "";
foreach ($g_gametype_3d as $gameid => $val)
{
    if (isset($checkedArr[$gameid]))
    {
        $ch = $g_gametype_3d[$gameid]['ch'];
        $en = $g_gametype_3d[$gameid]['en'];
        $gametypeCHK .= " <label class=paper{$en}><input type=\"checkbox\" value=\"{$gameid}\" name=\"chkGame[]\" id=\"chkGame_{$gameid}\" {$checkedArr[$gameid]} />{$ch}</label>";
    }
}
foreach ($chkRameArr as $val)
{
    $tpl->set("chkRame" . $val, "checked");
}
$tpl->load("main", "chkbet.htm");
$tpl->set(array("gametypeCHK" => $gametypeCHK, "dataList" => $dataList, "page" => $page, "pagelink" => $pagelink, "dt1" => $dt1, "dt2" => $dt2, "gametype" => $gametype, "user_id" => $user_id));
$ui->header();
$ui->load("calendar_js", "calendar_js.htm");
$ui->show("calendar_js");
include( "admin_menu_3d.php" );
echo title("【异常注单检查】");
$tpl->show("main");
$ui->footer();
?>